<template>
	<view class="main bgfff">
		<gui-a-header title="编辑简历"></gui-a-header>
		<view class="warp">
			<view class="card">
				<view class="title-img flex-ac">
					<image src="@/static/image/userInfo.png" mode="widthFix" style="height: auto;"></image>
					<text class="f28 gui-bold">个人信息</text>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26 mt30">
					<view class="label c333">
						头像<!-- <text class="c999">（建议使用真人照片）</text> -->
					</view>
					<view class="val">
						<gui-upload-images :items="logoFileList" @change="changeTx" ref="uploadimgTx" :maxFileNumber="1"
							@uploaded="uploadedTx"
							:uploadServerUrl="`${baseURL}/common/uploadLocal`"></gui-upload-images>
					</view>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26">
					<view class="label c333">
						姓名
					</view>
					<view class="val c333">
						<input class="val_input" type="text" v-model="cvForm.userName" placeholder="请输入姓名" />
					</view>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26">
					<view class="label c333">
						性别
					</view>
					<picker @change="sexPickerChange" :value="sexIndex" :range="sexArr" range-key="dictLabel">
						<view class="val gui-flex gui-align-items-center c333">
							<view class="uni-input">{{ sexArr[sexIndex].dictLabel }}</view>
							<text class="gui-icons c999">&#xe601;</text>
						</view>
					</picker>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26">
					<view class="label c333">
						年龄
					</view>
					<view class="val c333">
						<input class="val_input" type="text" v-model="cvForm.userAge" placeholder="请输入年龄" />
					</view>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26">
					<view class="label c333">
						学历
					</view>
					<view class="val c333">
						<picker @change="educationPickerChange" :value="educationIndex" :range="educationArr"
							range-key="dictLabel">
							<view class="val gui-flex gui-align-items-center c333">
								<view class="uni-input" v-if="educationArr[educationIndex]">
									{{ educationArr[educationIndex].dictLabel }}</view>
								<text class="gui-icons c999">&#xe601;</text>
							</view>
						</picker>
					</view>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26">
					<view class="label c333">
						工作经验
					</view>
					<view class="val c333">
						<input class="val_input" type="text" v-model="cvForm.workTime" placeholder="请输入工作经验" />
					</view>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26">
					<view class="label c333">
						现居地
					</view>
					<view class="val c333">
						<!-- <picker @change="bindPickerChange" :value="nowAddressIndex" mode="region">
							<view class="uni-input" v-if="nowAddressData.length > 0">
								{{nowAddressData[0]+'-'+nowAddressData[1]+'-'+nowAddressData[2]}}
							</view>
							<view class="c999" v-else>
								请选择现居地
							</view>
						</picker> -->
						<picker @change="nowAddressPickerChange" :value="nowAddressIndex" :range="workAreaArr"
							range-key="dictLabel">
							<view class="val gui-flex gui-align-items-center c333">
								<view class="uni-input">{{ workAreaArr[nowAddressIndex].dictLabel }}</view>
								<text class="gui-icons c999">&#xe601;</text>
							</view>
						</picker>
					</view>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26">
					<view class="label c333">
						户籍所在地
					</view>
					<view class="val c333">
						<picker @change="bindOldAddressPickerChange" :value="oldAddressIndex" mode="region">
							<view class="uni-input" v-if="oldAddressData.length > 0">
								{{ oldAddressData[0] + '-' + oldAddressData[1] + '-' + oldAddressData[2] }}
							</view>
							<view class="c999" v-else>
								请选择户籍所在地
							</view>
						</picker>
					</view>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26">
					<view class="label c333">
						手机号
					</view>
					<view class="val c333">
						<input class="val_input" type="text" v-model="cvForm.userPhone" placeholder="请输入手机号" />
					</view>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26">
					<view class="label c333">
						邮箱
					</view>
					<view class="val c333">
						<input class="val_input" type="text" v-model="cvForm.userEmail" placeholder="请输入邮箱" />
					</view>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26">
					<view class="label c333">
						求职状态
					</view>
					<view class="val c333">
						<picker @change="workStatusPickerChange" :value="workStatusIndex" :range="workStatusArr"
							range-key="dictLabel">
							<view class="val gui-flex gui-align-items-center c333">
								<view class="uni-input">{{ workStatusArr[workStatusIndex].dictLabel }}</view>
								<text class="gui-icons c999">&#xe601;</text>
							</view>
						</picker>
					</view>
				</view>
			</view>
			<view class="zw_10"></view>
			<view class="card">
				<view class="title-img flex-ac">
					<image src="@/static/image/userInfo.png" mode="widthFix" style="height: auto;"></image>
					<text class="f28 gui-bold">残疾信息</text>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26">
					<view class="label c333">
						残疾证号
					</view>
					<view class="val c333">
						<input class="val_input" type="text" v-model="cvForm.physicalNo" placeholder="请输入残疾证号" />
					</view>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26">
					<view class="label c333">
						残疾类别
					</view>
					<view class="val c333">
						<picker @change="physicalTypePickerChange" :value="physicalTypeIndex" :range="physicalTypeArr"
							range-key="dictLabel">
							<view class="val gui-flex gui-align-items-center c333">
								<view class="uni-input">{{ physicalTypeArr[physicalTypeIndex].dictLabel }}</view>
								<text class="gui-icons c999">&#xe601;</text>
							</view>
						</picker>
					</view>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26">
					<view class="label c333">
						残疾等级
					</view>
					<view class="val c333">
						<picker @change="physicalGradePickerChange" :value="physicalGradeIndex"
							:range="physicalGradeArr" range-key="dictLabel">
							<view class="val gui-flex gui-align-items-center c333">
								<view class="uni-input">{{ physicalGradeArr[physicalGradeIndex].dictLabel }}</view>
								<text class="gui-icons c999">&#xe601;</text>
							</view>
						</picker>
					</view>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26"
					v-if="physicalTypeArr[physicalTypeIndex].dictCode == 59">
					<view class="label c333">
						肢体残疾部位
					</view>
					<view class="val c333">
						<input class="val_input" type="text" v-model="cvForm.physicalPart" placeholder="请输入肢体残疾部位" />
					</view>
				</view>
				<view class="row gui-flex gui-space-between gui-align-items-center f26"
					v-if="physicalTypeArr[physicalTypeIndex].dictCode == 62">
					<view class="label c333">
						多重残疾情况
					</view>
					<view class="val c333">
						<input class="val_input" type="text" v-model="cvForm.physicalTypeVar" placeholder="请输入多重残疾情况" />
					</view>
				</view>
			</view>
			<view class="zw_10"></view>
			<view class="card">
				<view class="title-img flex-ac gui-space-between">
					<view class="left">
						<image src="@/static/image/jyjl.png" mode="widthFix" style="height: auto;"></image>
						<text class="f28 gui-bold">教育经历</text>
					</view>
					<view class="tool f38" @click="addUserEducation">
						<text class="bai-icons">&#xe6de;</text>
					</view>
				</view>
				<view class="border" v-for="(item, index) in cvForm.comUserEducationList" :key="index">
					<view class="del" @click="delUserEducation(index)">
						<text class="gui-icons">&#xe794;</text>
					</view>
					<view class="row gui-flex gui-space-between gui-align-items-center f26">
						<view class="label c333">
							学校名称
						</view>
						<view class="val c333">
							<input class="val_input" type="text" v-model="item.schoolName" placeholder="请输入学校名称" />
						</view>
					</view>
					<view class="row gui-flex gui-space-between gui-align-items-center f26">
						<view class="label c333">
							时间
						</view>
						<gui-datetime-between @confirm="edConfirm($event, index)" :startValue="item.startTime"
							:endValue="item.endTime" :isTime="false">
							<view class="val c333">
								<text class="demo gui-block" v-if="item.endTime">{{ item.endTime == '' ? item.startTime :
							item.startTime + ' - ' + item.endTime }}</text>
								<text class="demo gui-block c999" v-else>请选择</text>
							</view>
						</gui-datetime-between>
					</view>
					<view class="row gui-flex gui-space-between gui-align-items-center f26">
						<view class="label c333">
							专业
						</view>
						<view class="val c333">
							<input class="val_input" type="text" v-model="item.speciality" placeholder="请输入专业" />
						</view>
					</view>
				</view>
			</view>
			<view class="zw_10"></view>
			<view class="card">
				<view class="title-img flex-ac gui-space-between">
					<view class="left">
						<image src="@/static/image/qzyx.png" mode="widthFix" style="height: auto;"></image>
						<text class="f28 gui-bold">求职意向</text>
					</view>
					<view class="tool f38" @click="addUserJobHuntList">
						<text class="bai-icons">&#xe6de;</text>
					</view>
				</view>
				<view class="border" v-for="(item, index) in cvForm.comUserJobHuntList" :key="index">
					<view class="del" @click="delUserJobHuntList(index)">
						<text class="gui-icons">&#xe794;</text>
					</view>
					<view class="row gui-flex gui-space-between gui-align-items-center f26">
						<view class="label c333">
							行业
						</view>
						<view class="val c333" @click="openIndustry(index, item)">
							<text v-if="item.industry">{{ item.industry }}</text>
							<text v-else class="c999">请选择</text>
							<!-- <picker @change="professionPickerChange($event, index)" :value="professionIndex[index]"
								:range="professionArr" range-key="dictLabel">
								<view class="val gui-flex gui-align-items-center c333">
									<view class="uni-input">{{professionArr[professionIndex[index]].dictLabel}}</view>
									<text class="gui-icons c999">&#xe601;</text>
								</view>
							</picker> -->
						</view>
					</view>
					<view class="row gui-flex gui-space-between gui-align-items-center f26">
						<view class="label c333">
							岗位
						</view>
						<view class="val c333">
							<input class="val_input" type="text" v-model="item.postName" placeholder="请输入岗位" />
						</view>
					</view>
					<view class="row gui-flex gui-space-between gui-align-items-center f26">
						<view class="label c333">
							薪资
						</view>
						<picker @change="postMoneyPickerChange($event, index)" :value="postMoneyIndex[index]"
							:range="postMoneyArr" range-key="dictLabel">
							<view class="val gui-flex gui-align-items-center c333">
								<view class="uni-input">{{ postMoneyArr[postMoneyIndex[index]].dictLabel }}</view>
								<text class="gui-icons c999">&#xe601;</text>
							</view>
						</picker>
					</view>
					<view class="row gui-flex gui-space-between gui-align-items-center f26">
						<view class="label c333">
							地点
						</view>
						<picker @change="workAreaPickerChange($event, index)" :value="workAreaIndex[index]"
							:range="workAreaArr" range-key="dictLabel">
							<view class="val gui-flex gui-align-items-center c333">
								<view class="uni-input">{{ workAreaArr[workAreaIndex[index]].dictLabel }}</view>
								<text class="gui-icons c999">&#xe601;</text>
							</view>
						</picker>
					</view>
				</view>
			</view>
			<view class="zw_10"></view>
			<view class="card">
				<view class="title-img flex-ac gui-space-between">
					<view class="left">
						<image src="@/static/image/gzjl.png" mode="widthFix" style="height: auto;"></image>
						<text class="f28 gui-bold">工作经历</text>
					</view>
					<view class="tool f38" @click="addUserCompanyList">
						<text class="bai-icons">&#xe6de;</text>
					</view>
				</view>
				<view class="border" v-for="(item, index) in cvForm.comUserCompanyList" :key="index">
					<view class="del" @click="delUserCompanyList(index)">
						<text class="gui-icons">&#xe794;</text>
					</view>
					<view class="row gui-flex gui-space-between gui-align-items-center f26">
						<view class="label c333">
							公司名称
						</view>
						<view class="val c333">
							<input class="val_input" type="text" v-model="item.companyName" placeholder="请输入公司名称" />
						</view>
					</view>
					<view class="row gui-flex gui-space-between gui-align-items-center f26">
						<view class="label c333">
							时间
						</view>
						<gui-datetime-between @confirm="companyTimeConfirm($event, index)" :startValue="item.startTime"
							:endValue="item.endTime" :isTime="false">
							<view class="val c333">
								<text class="demo gui-block" v-if="item.endTime">{{ item.endTime == '' ? item.startTime :
							item.startTime + ' - ' + item.endTime }}</text>
								<text class="demo gui-block c999" v-else>请选择</text>
							</view>
						</gui-datetime-between>
					</view>
					<view class="row gui-flex gui-space-between gui-align-items-center f26">
						<view class="label c333">
							岗位
						</view>
						<view class="val c333">
							<input class="val_input" type="text" v-model="item.postName" placeholder="请输入岗位" />
						</view>
					</view>
					<view class="row gui-flex gui-space-between gui-align-items-center f26">
						<view class="label c333">
							内容
						</view>
						<view class="val c333">
							<input class="val_input" type="text" v-model="item.context" placeholder="请输入内容" />
						</view>
					</view>
				</view>
			</view>
			<view class="btn_warp gui-flex">
				<view class="btn line_right" @click="draftSumbit">
					暂时保存
				</view>
				<view class="btn" @click="realSumbit">
					确定
				</view>
			</view>
			<pickerIndustry ref="pickerIndustryRef" :professionData="professionData" @confirm="professionConfirm" />
		</view>
	</view>
</template>

<script setup>
import {
	useUserStore
} from '@/stores/user.js'
const store = useUserStore()
import graceChecker from "@/Grace6/js/checker.js"
import pickerIndustry from "@/components/picker-industry/index.vue"

import {
	ref,
	reactive,
	inject
} from 'vue'

import {
	getSysDictTypeList,
	selectOneGradeList
} from '@/api/config.js';

import {
	inertUserInfo,
	inertUserInfoCG,
	getUserInfoShNull
} from '@/api/user.js';

import config from '@/config/app.js'

import {
	onLoad,
	onUnload
} from '@dcloudio/uni-app'

const pickerIndustryRef = ref(null)

const openIndustry = (index, item) => {
	let industryId = '';
	if (item.industryId) {
		industryId = item.industryId;
	}
	pickerIndustryRef.value.open(index, industryId);
}

let timer;
const isClick = ref(true);

onUnload(() => {
	if (timer) clearTimeout(timer);
})

const {
	baseURL
} = config;

const $u = reactive(inject('$u'))

const cvForm = ref({
	userImg: '',
	userName: '', // 姓名
	userSex: '', // 性别
	userAge: '', // 年龄
	workTime: '', // 工作经验
	nowAddress: '', // 现居地
	oldAddress: '', // 户籍所在地
	userPhone: '', // 用户手机号
	userEmail: '', // 用户邮箱
	workStatus: '', // 求职状态
	physicalNo: '', // 残疾号
	physicalType: '', // 残疾类型
	physicalGrade: '', // 残疾等级
	physicalPart: '', // 肢体残疾部位
	physicalTypeVar: '',// 多重残疾情况
	comUserEducationList: [], //教育经历
	comUserJobHuntList: [], //求职意向
	comUserCompanyList: []
})
// const nowAddressIndex = ref(-1);
const nowAddressData = ref([])
const oldAddressIndex = ref(-1);
const oldAddressData = ref([])
const jobIndex = ref(0)
const levelIndex = ref(0)

const bindOldAddressPickerChange = (e) => {
	oldAddressData.value = e.detail.value;
	cvForm.value.oldAddress = e.detail.value[0] + '-' + e.detail.value[1] + '-' + e.detail.value[2]
}

// 是否为草稿
const isDraft = ref(false)

const radioChange = (e) => {
	console.log(e);
}
// 是否上传完成了
const logoFileList = ref([]);
const uploadFilePross = ref([true])
const uploadimgTx = ref(null);
// logo上传
const changeTx = (e) => {
	console.log(e);
	let list = e.filter((item) => {
		return item.progress == 0
	})
	if (list.length > 0) uploadFilePross.value[0] = false;
}
const uploadedTx = (uploadedImgs) => {
	cvForm.value.userImg = uploadedImgs[0].url;
	uploadFilePross.value[0] = true;
	if (isDraft.value) {
		draftSumbit();
	} else {
		realSumbit();
	}
}

const sexArr = ref([{
	dictLabel: '请选择',
	dictValue: ''
}])
const sexIndex = ref(0)
const sexPickerChange = (e) => {
	sexIndex.value = e.detail.value;
	cvForm.value.userSex = sexArr.value[e.detail.value].dictValue
}

const workStatusArr = ref([{
	dictLabel: '请选择',
	dictValue: ''
}])
const workStatusIndex = ref(0)
const workStatusPickerChange = (e) => {
	workStatusIndex.value = e.detail.value;
	cvForm.value.workStatus = workStatusArr.value[e.detail.value].dictValue
}

const physicalTypeArr = ref([{
	dictLabel: '请选择',
	dictValue: ''
}])
const physicalTypeIndex = ref(0)
const physicalTypePickerChange = (e) => {
	physicalTypeIndex.value = e.detail.value;
	cvForm.value.physicalType = physicalTypeArr.value[e.detail.value].dictValue
}

const physicalGradeArr = ref([{
	dictLabel: '请选择',
	dictValue: ''
}])
const physicalGradeIndex = ref(0)
const physicalGradePickerChange = (e) => {
	physicalGradeIndex.value = e.detail.value;
	cvForm.value.physicalGrade = physicalGradeArr.value[e.detail.value].dictValue
}

const professionData = ref([]);
const professionArr = ref([{
	dictLabel: '请选择',
	dictValue: ''
}])
const professionIndex = ref([])
const professionPickerChange = (e, index) => {
	professionIndex.value[index] = e.detail.value;
	cvForm.value.comUserJobHuntList[index].industry = professionArr.value[e.detail.value].dictValue
}

const professionConfirm = (data) => {
	console.log(data);
	cvForm.value.comUserJobHuntList[data.index].industryId = professionData.value[data.value[0]].listGrade[data.value[1]].id
	cvForm.value.comUserJobHuntList[data.index].industry = professionData.value[data.value[0]].listGrade[data.value[1]].twoName
}

const postMoneyArr = ref([{
	dictLabel: '请选择',
	dictValue: ''
}])
const postMoneyIndex = ref([])
const postMoneyPickerChange = (e, index) => {
	postMoneyIndex.value[index] = e.detail.value;
	cvForm.value.comUserJobHuntList[index].moneyPages = postMoneyArr.value[e.detail.value].dictValue
}


const nowAddressIndex = ref(0)
const nowAddressPickerChange = (e, index) => {
	nowAddressIndex.value = e.detail.value;
	cvForm.value.nowAddress = workAreaArr.value[e.detail.value].dictValue;
	console.log(cvForm.value);
}

const workAreaArr = ref([{
	dictLabel: '请选择',
	dictValue: ''
}])
const workAreaIndex = ref([])
const workAreaPickerChange = (e, index) => {
	workAreaIndex.value[index] = e.detail.value;
	cvForm.value.comUserJobHuntList[index].addressName = workAreaArr.value[e.detail.value].dictValue
}

const educationArr = ref([{
	dictLabel: '请选择',
	dictValue: ''
}])
const educationIndex = ref(0)
const educationPickerChange = (e, index) => {
	educationIndex.value = e.detail.value;
	cvForm.value.education = educationArr.value[e.detail.value].dictValue
}

// 添加教育经历
const addUserEducation = () => {
	let jxVal = true;
	let msg = '';
	cvForm.value.comUserEducationList.some((item, index) => {
		if (!item.schoolName) {
			jxVal = false;
			msg = "学校名称";
			return true;
		}
		if (!item.startTime) {
			msg = "时间";
			jxVal = false;
			return true;
		}
		if (!item.endTime) {
			msg = "时间";
			jxVal = false;
			return true;
		}
		if (!item.speciality) {
			msg = "专业";
			jxVal = false;
			return true;
		}
	})
	if (!jxVal) {
		$u.msg(`请补充完善${msg}信息再添加`)
		return;
	}
	cvForm.value.comUserEducationList.push({
		schoolName: '',
		startTime: '',
		endTime: '',
		speciality: ''
	})
}

const delUserEducation = (index) => {
	cvForm.value.comUserEducationList.splice(index, 1);
}

// 添加工作经历
const addUserCompanyList = () => {
	let jxVal = true;
	let msg = '';
	cvForm.value.comUserCompanyList.some((item, index) => {
		if (!item.companyName) {
			jxVal = false;
			msg = "公司名称";
			return true;
		}
		if (!item.startTime) {
			msg = "时间";
			jxVal = false;
			return true;
		}
		if (!item.endTime) {
			msg = "时间";
			jxVal = false;
			return true;
		}
		if (!item.postName) {
			msg = "岗位";
			jxVal = false;
			return true;
		}
		if (!item.context) {
			msg = "内容";
			jxVal = false;
			return true;
		}
	})
	if (!jxVal) {
		$u.msg(`请补充完善${msg}信息再添加`)
		return;
	}
	cvForm.value.comUserCompanyList.push({
		companyName: '',
		startTime: '',
		endTime: '',
		postName: '',
		context: ''
	})
}

const delUserCompanyList = (index) => {
	cvForm.value.comUserCompanyList.splice(index, 1);
}

// 添加求职意向
const addUserJobHuntList = () => {
	let jxVal = true;
	let msg = '';
	cvForm.value.comUserJobHuntList.some((item, index) => {
		if (!item.postName) {
			msg = "岗位";
			jxVal = false;
			return true;
		}
	})
	if (!jxVal) {
		$u.msg(`请补充完善${msg}信息再添加`)
		return;
	}
	professionIndex.value.push(0);
	workAreaIndex.value.push(0);
	postMoneyIndex.value.push(0);
	setTimeout(() => {
		cvForm.value.comUserJobHuntList.push({
			industry: '',
			postName: '',
			moneyPages: postMoneyArr.value[0].dictValue,
			addressName: workAreaArr.value[0].dictValue
		})
	}, 100)
}

const delUserJobHuntList = (index) => {
	cvForm.value.comUserJobHuntList.splice(index, 1);
}

const edConfirm = (res, index) => {
	cvForm.value.comUserEducationList[index].startTime = res[0][0] + '-' + res[0][1] + '-' + res[0][2];
	cvForm.value.comUserEducationList[index].endTime = res[1][0] + '-' + res[1][1] + '-' + res[1][2];
}

const companyTimeConfirm = (res, index) => {
	cvForm.value.comUserCompanyList[index].startTime = res[0][0] + '-' + res[0][1] + '-' + res[0][2];
	cvForm.value.comUserCompanyList[index].endTime = res[1][0] + '-' + res[1][1] + '-' + res[1][2];
}

const loadZd = () => {
	selectOneGradeList().then(res => {
		professionData.value = res.data;
		getSysDictTypeList({
			dictType: ''
		}).then(res => {
			let result = res.data;
			sexArr.value = [];
			workStatusArr.value = [];
			physicalTypeArr.value = [];
			physicalGradeArr.value = [];
			professionArr.value = [];
			workAreaArr.value = [];
			postMoneyArr.value = [];
			educationArr.value = [];
			result.forEach(item => {
				if (item.dictType == 'sys_user_sex') {
					sexArr.value.push(item)
				}
				if (item.dictType == 'com_work_status') {
					workStatusArr.value.push(item)
				}
				if (item.dictType == 'com_physical_type') {
					physicalTypeArr.value.push(item)
				}
				if (item.dictType == 'com_disability_level') {
					physicalGradeArr.value.push(item)
				}
				if (item.dictType == 'com_industry') {
					professionArr.value.push(item)
				}
				if (item.dictType == 'com_work_area') {
					workAreaArr.value.push(item)
				}
				if (item.dictType == 'com_salary') {
					postMoneyArr.value.push(item)
				}
				if (item.dictType == 'com_education_info') {
					educationArr.value.push(item)
				}
			})
			loadDetails();
		})
	})

}
loadZd();

const realSumbit = () => {
	isDraft.value = false;
	if (!uploadFilePross.value[0]) {
		uploadimgTx.value.upload();
		return;
	}
	//定义表单规则
	let rule = [{
		name: 'userImg',
		checkType: 'notnull',
		errorMsg: '请上传头像'
	}, {
		name: 'userName',
		checkType: 'notnull',
		errorMsg: '请输入姓名'
	}, {
		name: 'userAge',
		checkType: 'notnull',
		errorMsg: '请输入年龄'
	}, {
		name: 'workTime',
		checkType: 'notnull',
		errorMsg: '请输入工作经验'
	}, {
		name: 'userPhone',
		checkType: 'phoneno',
		errorMsg: '手机号格式有误'
	}];
	let checkRes = graceChecker.check(cvForm.value, rule);
	if (checkRes) {
		if (!jy()) return;
		if (isClick.value) {
			isClick.value = false;
		} else {
			return;
		}
		let form = Object.assign(cvForm.value, {})
		inertUserInfo(form).then(res => {
			if (res.code == 200) {
				$u.msg('已保存');
				uni.$emit('curriculumUpdate')
				store.getUserFun();
				timer = setTimeout(() => {
					$u.back();
				}, 500)
			} else {
				$u.msg(res.msg);
			}
		}).finally(() => {
			isClick.value = true;
		})
	} else {
		$u.msg(graceChecker.error);
	}
}

const draftSumbit = () => {
	isDraft.value = true;
	if (!uploadFilePross.value[0]) {
		uploadimgTx.value.upload();
		return;
	}
	//定义表单规则
	let rule = [{
		name: 'userImg',
		checkType: 'notnull',
		errorMsg: '请上传头像'
	}, {
		name: 'userName',
		checkType: 'notnull',
		errorMsg: '请输入姓名'
	}, {
		name: 'userAge',
		checkType: 'notnull',
		errorMsg: '请输入年龄'
	}, {
		name: 'workTime',
		checkType: 'notnull',
		errorMsg: '请输入工作经验'
	}, {
		name: 'userPhone',
		checkType: 'phoneno',
		errorMsg: '手机号格式有误'
	}, {
		name: 'physicalNo',
		checkType: 'notnull',
		errorMsg: '请输入残疾证号'
	}, {
		name: 'physicalPart',
		checkType: 'notnull',
		errorMsg: '请输入肢体残疾部位'
	}];
	let checkRes = graceChecker.check(cvForm.value, rule);
	if (checkRes) {
		if (!jy()) return;
		if (isClick.value) {
			isClick.value = false;
		} else {
			return;
		}
		let form = Object.assign(cvForm.value, {})
		inertUserInfoCG(form).then(res => {
			if (res.code == 200) {
				$u.msg('已保存为草稿');
			} else {
				$u.msg(res.msg);
			}
		}).finally(() => {
			isClick.value = true;
		})
	} else {
		$u.msg(graceChecker.error);
	}
}

const loadDetails = () => {
	getUserInfoShNull().then(res => {
		if (res.code == 200 && res.data) {
			cvForm.value = res.data;
			let result = res.data;
			oldAddressData.value = res.data.oldAddress.split('-');
			cvForm.value.oldAddress = res.data.oldAddress;
			professionIndex.value = [];
			workAreaIndex.value = [];
			postMoneyIndex.value = [];
			result.comUserJobHuntList.forEach(item => {
				professionIndex.value.push(0);
				workAreaIndex.value.push(0);
				postMoneyIndex.value.push(0);
			})
			if (result.userImg) logoFileList.value = [result.userImg];
			sexArr.value.forEach((item, index) => {
				if (item.dictValue == result.userSex) sexIndex.value = index;
			})
			workStatusArr.value.forEach((item, index) => {
				if (item.dictValue == result.workStatus) workStatusIndex.value = index;
			})
			workAreaArr.value.forEach((item, index) => {
				if (item.dictValue == result.nowAddress) nowAddressIndex.value = index;
			})
			physicalGradeArr.value.forEach((item, index) => {
				if (item.dictValue == result.physicalGrade) physicalGradeIndex.value = index;
			})
			physicalTypeArr.value.forEach((item, index) => {
				if (item.dictValue == result.physicalType) physicalTypeIndex.value = index;
			})
			educationArr.value.forEach((item, index) => {
				if (item.dictValue == result.education) educationIndex.value = index;
			})
			professionArr.value.forEach((item, index) => {
				result.comUserJobHuntList.forEach((cItem, cIndex) => {
					if (item.dictValue == cItem.industry) professionIndex.value[cIndex] =
						index;
				})
			})
			postMoneyArr.value.forEach((item, index) => {
				result.comUserJobHuntList.forEach((cItem, cIndex) => {
					if (item.dictValue == cItem.moneyPages) postMoneyIndex.value[cIndex] =
						index;
				})
			})
			workAreaArr.value.forEach((item, index) => {
				result.comUserJobHuntList.forEach((cItem, cIndex) => {
					if (item.dictValue == cItem.addressName) workAreaIndex.value[cIndex] =
						index;
				})
			})
		} else {
			cvForm.value.userSex = sexArr.value[0].dictValue;
			cvForm.value.workStatus = workStatusArr.value[0].dictValue;
			cvForm.value.nowAddress = workAreaArr.value[0].dictValue;
			cvForm.value.physicalGrade = physicalGradeArr.value[0].dictValue;
			cvForm.value.physicalType = physicalTypeArr.value[0].dictValue;
			cvForm.value.education = educationArr.value[0].dictValue;
			if (cvForm.value.comUserJobHuntList.length > 0) {
				cvForm.value.comUserJobHuntList[0].industry = professionArr.value[0].dictValue;
				cvForm.value.comUserJobHuntList[0].moneyPages = postMoneyArr.value[0].dictValue;
				cvForm.value.comUserJobHuntList[0].addressName = workAreaArr.value[0].dictValue;
			}
		}
	})
}

const jy = () => {
	let jxVal = true;
	let msg = '';
	cvForm.value.comUserEducationList.some((item, index) => {
		if (!item.schoolName) {
			jxVal = false;
			msg = `教育经历第${index + 1}条学校名称`;
			return true;
		}
		if (!item.startTime) {
			msg = `教育经历第${index + 1}条时间`;
			jxVal = false;
			return true;
		}
		if (!item.endTime) {
			msg = `教育经历第${index + 1}条时间`;
			jxVal = false;
			return true;
		}
		if (!item.speciality) {
			msg = `教育经历第${index + 1}条专业`;
			jxVal = false;
			return true;
		}
	})
	if (!jxVal) {
		$u.msg(`请补充完善${msg}信息再添加`)
		return false;
	}

	cvForm.value.comUserJobHuntList.some((item, index) => {
		if (!item.postName) {
			msg = `求职意向第${index + 1}条岗位`;
			jxVal = false;
			return true;
		}
	})
	if (!jxVal) {
		$u.msg(`请补充完善${msg}信息再添加`)
		return false;
	}

	cvForm.value.comUserCompanyList.some((item, index) => {
		if (!item.companyName) {
			jxVal = false;
			msg = `工作经历第${index + 1}条公司名称`;
			return true;
		}
		if (!item.startTime) {
			msg = `工作经历第${index + 1}条时间`;
			jxVal = false;
			return true;
		}
		if (!item.endTime) {
			msg = `工作经历第${index + 1}条时间`;
			jxVal = false;
			return true;
		}
		if (!item.postName) {
			msg = `工作经历第${index + 1}条岗位`;
			jxVal = false;
			return true;
		}
		if (!item.context) {
			msg = `工作经历第${index + 1}条内容`;
			jxVal = false;
			return true;
		}
	})
	if (!jxVal) {
		$u.msg(`请补充完善${msg}信息再添加`)
		return false;
	} else {
		return true;
	}
}
</script>

<style lang="scss">
.warp {
	box-sizing: border-box;
}

.card {
	box-sizing: border-box;
	padding: 20rpx 64rpx 0rpx 40rpx;

	.tool {
		position: relative;
		right: -40rpx;

		.bai-icons {
			color: #167C3A;
		}
	}
}

.title-img {
	padding: 20rpx 0;
}

.tx_image {
	width: 115rpx;
	height: 115rpx;
}

.row {
	padding: 24rpx 0;
	border-bottom: 1rpx solid #EBEBEB;
}

.val_input {
	text-align: right;
}

.zw_10 {
	width: 100%;
	height: 10rpx;
	background: #f8f9fd;
}

.border {
	position: relative;
	border-radius: 14rpx;
	padding: 0 20rpx;
	box-sizing: border-box;
	border: 1rpx solid rgba(64, 114, 254, 0.35);
	margin-bottom: 30rpx;

	.del {
		position: absolute;
		right: -46rpx;
		top: 50%;
		transform: translateY(-50%);
		color: #4072FE;
	}
}

.btn_warp {
	width: 750rpx;
	height: 89rpx;

	.btn {
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
		width: 50%;
		background: linear-gradient(180deg, #4072FE 0%, #0034C7 100%);
		font-size: 26rpx;

		&.line_right {
			position: relative;

			&::after {
				content: '';
				position: absolute;
				right: 0;
				height: 89rpx;
				width: 1rpx;
				background-color: #CCCCCC;
			}
		}
	}
}
</style>